REGION 初始化
    // Statement section REGION
    IF "FirstScan" THEN
        "上升优先" := 1;
        //所有的呼叫清零
        //
        #就绪信号1 := 0;
        "电梯当前所在楼层":=1;
POKE(area:=16#83,
     dbNumber:=0,
     byteOffset:=6,
     value:=#Static_1);
;
    END_IF;
    
END_REGION

REGION 电梯外面按钮被按的动作
    //在本层则打开门 不在本层则给一个呼叫状态
    IF "向上按钮楼1" THEN
        IF "电梯在楼1" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼1" := 1;
        END_IF;
        "向上按钮楼1" := 0;
    END_IF;
    IF "向上按钮楼2" THEN
        IF "电梯在楼2" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼2" := 1;
        END_IF;
        "向上按钮楼2" := 0;
    END_IF;
    IF "向上按钮楼3" THEN
        IF "电梯在楼3" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼3" := 1;
        END_IF;
        "向上按钮楼3" := 0;
    END_IF;
    IF "向上按钮楼4" THEN
        IF "电梯在楼4" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼4" := 1;
        END_IF;
        "向上按钮楼4" := 0;
    END_IF;
   
    
    IF "向下按钮楼2"  THEN
        IF "电梯在楼2" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼2" := 1;
        END_IF;
        "向下按钮楼2" := 0;
    END_IF;
    IF "向下按钮楼3" THEN
        IF "电梯在楼3" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼3" := 1;
        END_IF;
        "向下按钮楼3" := 0;
    END_IF;
    IF "向下按钮楼4" THEN
        IF "电梯在楼4" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼4" := 1;
        END_IF;
        "向下按钮楼4" := 0;
    END_IF;
    IF "向下按钮楼5" THEN
        IF "电梯在楼5" THEN
            "开门按钮" := 1;
        ELSE
            "楼层被呼叫状态楼5" := 1;
        END_IF;
        "向下按钮楼5" := 0;
    END_IF;

    
END_REGION

REGION 电梯里面按钮被按的动作
    //如果请求楼层大于当前楼层,给一个上升请求;反之,给一个下降请求
    IF "去楼1" THEN
        IF "电梯在楼1" THEN
            // Statement section IF
            "DB1".提示信息 := '当前就是在这楼,你个猪';
        ELSE
            "楼层被呼叫状态楼1" := 1;
          (*  IF "电梯当前所在楼层" > 1 THEN
                "电梯下降请求" := 1;
                "优先权" := -1;
            ELSE
                "电梯上升请求" := 1;
                "优先权" := 1;
            END_IF; *)
        END_IF;
        "去楼1" := 0;
    END_IF;
    
    IF "去楼2" THEN
        IF "电梯在楼2" THEN
            // Statement section IF
            "DB1".提示信息 := '当前就是在这楼,你个猪';
        ELSE
            "楼层被呼叫状态楼2" := 1;
           (* IF "电梯当前所在楼层" > 2 THEN
                "电梯下降请求" := 1;
                "优先权" := -1;
            ELSE
                "电梯上升请求" := 1;
                "优先权" := 1;
            END_IF; *)        
        END_IF;
        "去楼2" := 0;
    END_IF;
    
    IF "去楼3" THEN
        IF "电梯在楼3" THEN
            "DB1".提示信息 := '当前就是在这楼,你个猪';
        ELSE
            "楼层被呼叫状态楼3" := 1;
           (* IF "电梯当前所在楼层" > 3 THEN
                "电梯下降请求" := 1;
                "优先权" := -1;
            ELSE
                "电梯上升请求" := 1;
                "优先权" := 1;
            END_IF; *)
        END_IF;
        "去楼3" := 0;
    END_IF;
    
    IF "去楼4" THEN
        IF "电梯在楼4" THEN
            "DB1".提示信息 := '当前就是在这楼,你个猪';
        ELSE
            "楼层被呼叫状态楼4" := 1;
           (* IF "电梯当前所在楼层" > 4 THEN
                "电梯下降请求" := 1;
                "优先权" := -1;
            ELSE
                "电梯上升请求" := 1;
                "优先权" := 1;
            END_IF; *)
        END_IF;
        "去楼4" := 0;
    END_IF;
    
    IF "去楼5" THEN
        IF "电梯在楼5" THEN
            "DB1".提示信息 := '当前就是在这楼,你个猪';
        ELSE
            "楼层被呼叫状态楼5" := 1;
           (* IF "电梯当前所在楼层" > 5 THEN
                "电梯下降请求" := 1;
                "优先权" := -1;
            ELSE
                "电梯上升请求" := 1;
                "优先权" := 1;
            END_IF; *)
        END_IF;
        "去楼5" := 0;
    END_IF;
    

END_REGION

(* REGION 处理楼层被呼叫按钮
    
    IF "关门到位信号" AND "上升下将就绪信号" THEN
        // Statement section IF
        
        
        IF "楼层被呼叫状态楼1" THEN
            IF "电梯当前所在楼层" > 1 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                // Statement section IF
                "电梯下降" := 1;
            END_IF;
            IF "电梯当前所在楼层" < 1 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                "电梯上升" := 1;
            END_IF;
        END_IF;
        IF "楼层被呼叫状态楼2" THEN
            IF "电梯当前所在楼层" > 2 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                // Statement section IF
                "电梯下降" := 1;
            END_IF;
            IF "电梯当前所在楼层" < 2 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                "电梯上升" := 1;
            END_IF;
        END_IF;
        IF "楼层被呼叫状态楼3" THEN
            IF "电梯当前所在楼层" > 3 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                // Statement section IF
                "电梯下降" := 1;
            END_IF;
            IF "电梯当前所在楼层" < 3 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                "电梯上升" := 1;
            END_IF;
        END_IF;
        IF "楼层被呼叫状态楼4" THEN
            IF "电梯当前所在楼层" > 4 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                // Statement section IF
                "电梯下降" := 1;
            END_IF;
            IF "电梯当前所在楼层" < 4 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                "电梯上升" := 1;
            END_IF;
        END_IF;
        IF "楼层被呼叫状态楼5" THEN
            IF "电梯当前所在楼层" > 5 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                // Statement section IF
                "电梯下降" := 1;
            END_IF;
            IF "电梯当前所在楼层" < 5 AND "电梯上升" = 0 AND "电梯下降" = 0 THEN
                "电梯上升" := 1;
            END_IF;
        END_IF;
        
        
    END_IF;
    
    ;
END_REGION *)

REGION 每到一层后的动作
    //若果这层有被请求,则停下来,并判断改变上下优先 没有则更新一下当前楼层;
    IF "电梯在楼1" THEN
        IF "楼层被呼叫状态楼1" THEN
           // "上升下将就绪信号" := 0;
            #就绪信号1 := 0;
            "电梯下降" := 0;
            "电梯上升" := 0;
           "开门按钮" := 1;
            #到一楼(CLK:="电梯在楼1",
                 Q=>#t1);
            IF #t1 THEN
                "开门按钮" := 1;
                ;
            END_IF;
        END_IF;
        "电梯当前所在楼层" := 1;
        "楼层被呼叫状态楼1" := 0;
        
    END_IF;
    IF "电梯在楼2" THEN
        IF "楼层被呼叫状态楼2" THEN
            //   "上升下将就绪信号" := 0;
            "电梯下降" := 0;
            "电梯上升" := 0;
            #就绪信号1 := 0;
           "开门按钮" := 1;
            #到二楼(CLK:="电梯在楼2",
                 Q=>"开门按钮");
            
            "楼层被呼叫状态楼2" := 0;
        END_IF;
        "电梯当前所在楼层" := 2;
        "楼层被呼叫状态楼2" := 0;
    END_IF;
    IF "电梯在楼3" THEN
        IF "楼层被呼叫状态楼3" THEN
         //   "上升下将就绪信号" := 0;
            "电梯下降" := 0;
            "电梯上升" := 0;
            #就绪信号1 := 0;
            "开门按钮" := 1;
            #到3楼(CLK:="电梯在楼3",
                 Q=>#t3);
            IF #t3 THEN
                "开门按钮" := 1;
                ;
            END_IF;
        END_IF;
        "电梯当前所在楼层" := 3;
        "楼层被呼叫状态楼3" := 0;
    END_IF;
    IF "电梯在楼4" THEN
        IF "楼层被呼叫状态楼4" THEN
            #就绪信号1 := 0;
            "上升下将就绪信号" := 0;
            "电梯下降" := 0;
            "电梯上升" := 0;
            "开门按钮" := 1;
            #就绪信号1 := 0;
            #到4楼(CLK:="电梯在楼4",
                 Q=>#t4);
            IF #t4 THEN
                "开门按钮" := 1;
                ;
            END_IF;
            
        END_IF;
        "电梯当前所在楼层" := 4;
        "楼层被呼叫状态楼4" := 0;
    END_IF;
    IF "电梯在楼5" THEN
        IF "楼层被呼叫状态楼5" THEN
            "上升下将就绪信号" := 0;
            "电梯下降" := 0;
            "电梯上升" := 0;
            "开门按钮" := 1;
            #就绪信号1 := 0;
            #到5楼(CLK := "电梯在楼5",
                 Q => #t5);
            IF #t5 THEN
                "开门按钮" := 1;
                ;
            END_IF;
        END_IF;
        "电梯当前所在楼层" := 5;
        "楼层被呼叫状态楼5":=0;
    END_IF;

 
    
END_REGION

REGION 处理开关门信号
    //电梯没在运转的情况下,才能开关门
    IF "开门按钮" AND "电梯上升" = 0 AND "电梯下降" = 0 AND "关门" = 0
        AND "开门到位信号" = 0 AND "开门" = 0 THEN
        "上升下将就绪信号" := 0;
        #就绪信号1 := 0;
        "开门" := 1;
        "开门按钮" := 0;
        // "关门到位信号" := 0;
        //  "关门按钮" := 0;
    END_IF;
    IF "开门到位信号" THEN
        "上升下将就绪信号" := 0;
        #就绪信号1 := 0;
        "开门" := 0;
        "开门按钮" := 0;
        //"关门" := 0;
        //   "开门按钮" := 0;
    END_IF;
    IF "关门按钮" AND "电梯上升" = 0 AND "电梯下降" = 0 AND "开门" = 0
        AND "关门到位信号" = 0 AND "关门" = 0 THEN
        // "开门按钮" := 0;
        "关门" := 1;
       // #就绪信号1 := 1;
        "关门按钮" := 0;
        // "开门到位信号" := 0;
    END_IF;
    IF "关门到位信号" THEN
        // "关门按钮" := 0;
        "关门" := 0;
        "关门按钮" := 0;
        #就绪信号1 := 1;
        // "开门" := 0;
     
    END_IF;
    
END_REGION

REGION 就绪信号
    // Statement section REGION
    IF #就绪信号1 AND
        ("楼层被呼叫状态楼1" = 1
        OR "楼层被呼叫状态楼2" = 1
        OR "楼层被呼叫状态楼3" = 1
        OR "楼层被呼叫状态楼4" = 1
        OR "楼层被呼叫状态楼5" = 1)
    THEN
        IF "上升优先" THEN
            CASE "电梯当前所在楼层" OF
                1:
                    ;
                2: //当前在二楼,且上优先,就需要判断在上面时候真的有请求,没有就将请求优先取消
                    IF "楼层被呼叫状态楼3" OR "楼层被呼叫状态楼4" OR "楼层被呼叫状态楼5" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 0;
                    END_IF;
                    
                    ;
                3:
                    IF "楼层被呼叫状态楼4" OR "楼层被呼叫状态楼5" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 0;
                    END_IF;
                    ;
                4:
                    IF "楼层被呼叫状态楼5" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 0;
                    END_IF;
                    ;
                5:
                    "上升优先" := 0;
                    ;
                    
                ELSE  // Statement section ELSE
                    ;
            END_CASE;
            ;
        ELSE //下降优先
            CASE "电梯当前所在楼层" OF
                1:
                    "上升优先" := 1;
                    ;
                2: //当前在二楼,且下降优先,就需要判断在下面的楼层是否真的有请求,没有就取消优先
                    IF "楼层被呼叫状态楼1" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 1;
                    END_IF;
                    
                    ;
                3:
                    IF "楼层被呼叫状态楼1" OR "楼层被呼叫状态楼2" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 1;
                    END_IF;
                    ;
                4:
                    IF "楼层被呼叫状态楼1" OR "楼层被呼叫状态楼2" OR "楼层被呼叫状态楼3" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 1;
                    END_IF;
                    ;
                5:
                    IF "楼层被呼叫状态楼1" OR "楼层被呼叫状态楼2" OR "楼层被呼叫状态楼3" OR "楼层被呼叫状态楼4" THEN
                        // Statement section IF
                        ;
                    ELSE
                        "上升优先" := 1;
                    END_IF;
                    ;
                    
                ELSE  // Statement section ELSE
                    ;
            END_CASE;
            ;
        END_IF;
        IF "上升优先" THEN
            "电梯上升" := 1;
            "电梯下降" := 0;
            ;
        ELSE
            "电梯下降" := 1;
            "电梯上升" := 0;
        END_IF;
        ;
    ELSE
        "电梯下降" := 0;
        "电梯上升" := 0;
    END_IF;
    
END_REGION





